﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;

namespace code
{
    public partial class Form1 : Form
    {

        string content1 = "";
        string content2 = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Task task_360 = new Task(() => SearchIn360());
            Task task_bing = new Task(() => SearchInbing());
            task_360.Start();
            task_bing.Start();
            task_360.Wait();
            task_bing.Wait();
            textBox2.Text = content1;
            textBox3.Text = content2;
        }
        private void SearchIn360()
        {
            WebClient client = new WebClient();
            client.Encoding= Encoding.UTF8; 
            string pageHtml = client.DownloadString("https://www.so.com/s?q=" + textBox1.Text);
            string pattern = @"[\u4e00-\u9fa5]*";
            Regex regex = new Regex(pattern);
            Match match = regex.Match(pageHtml);
            while (match.Success)
            {
                content1 += match.Value;
                match = match.NextMatch();
            }
            content1 = content1.Substring(0,200);
        }
        private void SearchInbing()
        {
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            string pageHtml = client.DownloadString("https://cn.bing.com/search?q=" + textBox1.Text);
            string pattern = @"[\u4e00-\u9fa5]*";
            MatchCollection matches = Regex.Matches(pageHtml, pattern);
            foreach (Match match in matches)
            {
                content2 += match.Value;
            }
            content2 = content2.Substring(0, 200);
        }
    }
}
